# --------------------------------------------
# function
# --------------------------------------------

snippet f "function" b
def
endsnippet

# --------------------------------------------
# logger
# --------------------------------------------

snippet lg
${2:LOGGER}.log("${1}")
endsnippet

snippet lgd
${2:LOGGER}.debug("${1}")
endsnippet

snippet lgi
${2:LOGGER}.info("${1}")
endsnippet

snippet lgw
${2:LOGGER}.warning("${1}")
endsnippet

snippet lge
${2:LOGGER}.error("${1}")
endsnippet

snippet lgex
${2:LOGGER}.exception("${1}")
endsnippet

snippet lgc
${2:LOGGER}.critical("${1}")
endsnippet

# --------------------------------------------
# dict
# --------------------------------------------

snippet dg "dict get"
${3:$2} = ${1:d}.get("${2:t}")
endsnippet

snippet dgs "dict get with square brackets" b
${3:$2} = ${1:d}["${2:t}"]
endsnippet


snippet dgd "dict get with default"
${4:$2} = ${1:d}.get("${2:t}", ${3:None})
endsnippet

snippet dgif "dict get if"
${3:$2} = ${1:d}.get("${2:t}")
if $2:
	${4:pass}
else:
	${5:pass}
endsnippet

snippet forkv "dict"
for ${1:key}, ${2:value} in ${3:d}.items():
	${0:pass}
endsnippet

snippet fork "dict"
for ${1:key} in ${2:d}:
	${0:pass}
endsnippet

snippet forv "dict"
for ${1:value} in ${2:d}.values():
	${0:pass}
endsnippet

snippet dfd "default dict"
import collections
${2:d} = collections.defaultdict(${1})
endsnippet

# --------------------------------------------
# attr
# --------------------------------------------

snippet geta "attr"
${2:attr} = getattr(${1:obj}, None)
endsnippet

snippet getaif "attr if True"
${3:attr} = getattr(${1:obj}, "${2:}", None)
if $3:
    ${4:pass}
endsnippet

# --------------------------------------------
# requests
# --------------------------------------------

snippet req "requests"
import requests
${0:r} = requests.request(${1:method}, ${2:url}, *args, **kwargs)
endsnippet

snippet reqget "requests"
import requests
${0:r} = requests.get(${1:url}, params=${2:None})
endsnippet

snippet reqpost "requests"
import requests
${0:r} = requests.post(${1:url}, data=${2:None}, json=${3:None})
endsnippet

snippet reqpatch "requests"
import requests
${0:r} = requests.patch(${1:url}, data=${2:None})
endsnippet

# --------------------------------------------
# path
# --------------------------------------------

snippet dirp "dir abspath" b
import os
os.path.dirname(os.path.abspath(__file__))
endsnippet

# --------------------------------------------
# import
# --------------------------------------------

snippet impurljoin "import urljoin" b
from urllib.parse import urljoin
endsnippet

# --------------------------------------------
# print
# --------------------------------------------

snippet ppr "import pprint and print" b
from pprint import pprint
pprint($1)
endsnippet

# --------------------------------------------
# doc
# --------------------------------------------

# snippet mdoc "Description" b
# endsnippet

snippet par "param in doc"
:param $1: $2
endsnippet

snippet ret "return in doc" b
:return: $0
endsnippet


# --------------------------------------------
# func
# --------------------------------------------

snippet ldef "lazy def with lazy doc" b
def ${1:func_name}():
    """ ${1/_/ /g} """
    ${0:pass}

endsnippet

# --------------------------------------------
# class
# --------------------------------------------

snippet _str "__str__ and __repr__" b
def __str__(self):
    return f"<{self.__class__.__name__}>"

__repr__ = __str__
endsnippet

# --------------------------------------------
# others
# --------------------------------------------

snippet singletonnew "Singleton via __new__" b
def __new__(cls, *args, **kw):
    if not hasattr(cls, '_instance'):
        cls._instance = super().__new__(cls, *args, **kw)
    return cls._instance
endsnippet

# snippet singletonnew2 "another Singleton via __new__" b
#     _state = {}
#     def __new__(cls, *args, **kw):
#         ob = super().__new__(cls, *args, **kw)
#         ob.__dict__ = cls._state
#         return ob
# endsnippet
